package vng.wcc.sonph.LauncherGenerator;

import android.content.Context;
import android.widget.LinearLayout;

public class LauncherRowView extends LinearLayout {

	private Formatter formatter;
	private CellInfo[] data;

	/**
	 * LauncherRowView is a row on the screen,
	 * it contains some cells - whose information is provided by data[]
	 * @param context 
	 * @param formatter provides layout information 
	 * @param data contains information about the items to be displayed (icon,title and intent to launch)
	 */
	public LauncherRowView(Context context,Formatter formatter,CellInfo[] data) {
		super(context);
		this.formatter = formatter;
		this.data = data;
		initView();
	}

	private void initView() {
		setViewLayout();
		addChildren();
	}

	/**
	 * Add children view of this row
	 */
	private void addChildren() {
		for(int i = 0 ; i < data.length ; i++ ) {
			//data[i] == null means: it doesn't contain any information - so: don't show it
			if ( data[i] != null ) {
				CellView cell = new CellView(this.getContext(), formatter, data[i]);
				this.addView(cell,formatter.getCellWidth(),formatter.getCellHeight());
			}
		}		
	}

	private void setViewLayout() {
		this.setPadding(0, 0, 0, 0);
		this.setOrientation(LinearLayout.HORIZONTAL);
	}
}
